<template>
  <div>
    <div style="margin: 20px 0">
      <a-button
        @click="callBack"
        type="primary"
        style="
          background: #66b1ff;
          color: #fff;
          border: none;
          margin-left: 20px;
        "
      >
        返回列表
      </a-button>
      <a-button
        :loading="downloadLoding"
        @click="exportFile"
        type="primary"
        style="
          background: #66b1ff;
          color: #fff;
          border: none;
          margin-left: 20px;
        "
      >
        导出明细 <a-icon icon="download" type="download" />
      </a-button>
    </div>
    <a-spin tip="Loading..." :spinning="spinning">
      <a-table
        :scroll="{ x: 1500 }"
        :columns="columns"
        :data-source="tableList"
        :pagination="false"
      >
        <span slot="updateTime" slot-scope="text, record">
          {{ record.updateTime.replaceAll("T", " ") }}
        </span>
        <span slot="createdTime" slot-scope="text, record">
          {{ record.createdTime.replaceAll("T", " ") }}
        </span>
      </a-table>
    </a-spin>
  </div>
</template>

<script>
import {
  issuing_olume_list,
  issuing_volume_list_outEx,
  transfer_volume_list,
  itransfer_volume_list_outEx,
} from "@/apis/system/marketing/curtomerData";
import req from "@/utils/req";
export default {
  props: ["pageType", "searchData", "rowData"],
  data() {
    return {
      spinning: false,
      tableList: [],
      downloadLoding: false,
    };
  },
  mounted() {
    if (this.pageType) {
      this.getTableList();
    }
  },
  methods: {
    //导出明细
    async exportFile() {
      this.downloadLoding = true;
      if (this.pageType == "issuingVolume") {
        let res = await issuing_volume_list_outEx({
          speId: this.rowData.speId,
          tenantId: this.rowData.tenantId,
          settlementCurrencyName: this.rowData.settlementCurrencyName,
          sysStoreHouseId: this.rowData.sysStoreHouseId,
          startDate: this.searchData.startDate
            ? null
            : this.searchData.startDate,
          endtDate: this.searchData.endtDate ? null : this.searchData.endtDate,
        });
        req.exportFile("客户数据代发体积", res);
        setTimeout(() => {
          this.downloadLoding = false;
        }, 1000);
      } else if (this.pageType == "transferVolume") {
        let file = await itransfer_volume_list_outEx({
          speId: this.rowData.speId,
          tenantId: this.rowData.tenantId,
          settlementCurrencyName: this.rowData.settlementCurrencyName,
          sysStoreHouseId: this.rowData.sysStoreHouseId,
          startDate: this.searchData.startDate
            ? null
            : this.searchData.startDate,
          endtDate: this.searchData.endtDate ? null : this.searchData.endtDate,
        });
        req.exportFile("客户数据转运体积", file);
        setTimeout(() => {
          this.downloadLoding = false;
        }, 1000);
      }
    },
    //返回列表
    callBack() {
      this.$emit("customerCallBack");
    },
    async getTableList() {
      this.spinning = true;

      if (this.pageType == "issuingVolume") {
        let { code, responseBody } = await issuing_olume_list({
          speId: this.rowData.speId,
          tenantId: this.rowData.tenantId,
          settlementCurrencyName: this.rowData.settlementCurrencyName,
          sysStoreHouseId: this.rowData.sysStoreHouseId,
          startDate: this.searchData.startDate
            ? null
            : this.searchData.startDate,
          endtDate: this.searchData.endtDate ? null : this.searchData.endtDate,
        });
        if (code == "200") {
          this.tableList = responseBody;
          this.spinning = false;
        }
      } else if (this.pageType == "transferVolume") {
        let { code, responseBody } = await transfer_volume_list({
          speId: this.rowData.speId,
          tenantId: this.rowData.tenantId,
          settlementCurrencyName: this.rowData.settlementCurrencyName,
          sysStoreHouseId: this.rowData.sysStoreHouseId,
          startDate: this.searchData.startDate
            ? null
            : this.searchData.startDate,
          endtDate: this.searchData.endtDate ? null : this.searchData.endtDate,
        });
        if (code == "200") {
          this.tableList = responseBody;
          this.spinning = false;
        }
      }
    },
  },
  computed: {
    columns() {
      switch (this.pageType) {
        case "issuingVolume":
          return [
            {
              title: "订单编号",
              dataIndex: "applyCode",
              align: "center",
              scopedSlots: { customRender: "applyCode" },
              //  fixed: "left",
            },
            {
              title: "SKU",
              dataIndex: "sku",
              align: "center",
              scopedSlots: { customRender: "sku" },
            },
            {
              title: "总体积（m³）",
              dataIndex: "issuingVolume",
              scopedSlots: { customRender: "issuingVolume" },
              align: "center",
            },
            {
              title: "到期数量（个数）",
              dataIndex: "nu",
              scopedSlots: { customRender: "nu" },
              align: "center",
              // ellipsis: true,
            },
            {
              title: "库龄（天）",
              dataIndex: "dayt",
              scopedSlots: { customRender: "dayt" },
              align: "center",
            },
            {
              title: "入库时间 ",
              dataIndex: "updateTime",
              scopedSlots: { customRender: "updateTime" },
              align: "center",
            },
          ];
        case "transferVolume":
          return [
            {
              title: "转运入库编号",
              dataIndex: "transferNo",
              align: "center",
              scopedSlots: { customRender: "transferNo" },
              //  fixed: "left",
            },
            {
              title: "货物编号",
              dataIndex: "goodsBoxNo",
              align: "center",
              scopedSlots: { customRender: "goodsBoxNo" },
            },
            {
              title: "总体积（m³）",
              dataIndex: "transferVolume",
              scopedSlots: { customRender: "transferVolume" },
              align: "center",
            },
            {
              title: "到期数量（箱数）",
              dataIndex: "total",
              scopedSlots: { customRender: "total" },
              align: "center",
              // ellipsis: true,
            },
            {
              title: "库龄（天）",
              dataIndex: "dayt",
              scopedSlots: { customRender: "dayt" },
              align: "center",
            },
            {
              title: "入库时间 ",
              dataIndex: "createdTime",
              scopedSlots: { customRender: "createdTime" },
              align: "center",
            },
          ];
        default:
          return [];
      }
    },
  },
};
</script>

<style lang="less" scoped>
</style>